/**
 * print.h
 *
 *  Created on: 2021.05.22
 *      Author: wangbing
 *      Email : mz8023yt@163.com
 */

#ifndef _MAZ_PRINT_H_
#define _MAZ_PRINT_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdio.h>

#define DERR        0   /* error */
#define DWAN        1   /* warning */
#define DINF        2   /* information */
#define DNTE        3   /* note */
#define DBG0        4   /* debug lvl high */
#define DBG1        5   /* debug lvl middle */
#define DBG2        6   /* debug lvl low */
#define IGN0        7   /* ignore lvl high */
#define IGN1        8   /* ignore lvl middle */
#define IGN2        9   /* ignore lvl low */

#define DCOM        DINF

#define DLVL2STR(dlvl)        \
    (DERR == dlvl) ? "DERR" : \
    (DWAN == dlvl) ? "DWAN" : \
    (DINF == dlvl) ? "DINF" : \
    (DNTE == dlvl) ? "DNTE" : \
    (DBG0 == dlvl) ? "DBG0" : \
    (DBG1 == dlvl) ? "DBG1" : \
    (DBG2 == dlvl) ? "DBG2" : \
    (IGN0 == dlvl) ? "IGN0" : \
    (IGN1 == dlvl) ? "IGN1" : \
    (IGN1 == dlvl) ? "IGN1" : "UKNOW"

/**
 * dmsg: debug message
 * dmsg: debug message with newline
 * dlog: debug log
 */
#define dmsg(lvl, fmt, arg...)  if(lvl <= dlvl) {                                                   \
                                    printf(fmt, ##arg);                                             \
                                }

#define dbug(lvl, fmt, arg...)  if(lvl <= dlvl) {                                                   \
                                    printf(fmt "\n", ##arg);                                        \
                                }

#define dlog(lvl, fmt, arg...)  if(lvl <= dlvl) {                                                   \
                                    printf("[%04d][%s] " fmt "\n", __LINE__, __FUNCTION__, ##arg);  \
                                }

#ifdef __cplusplus
}
#endif

#endif /* _MAZ_PRINT_H_ */
